import moment from 'moment';

export default class extends think.Service {
    constructor() {
        super();
        this.caseModel = this.db['oa_case'];
        this.orgModel = this.db['sys_org']
        this.userModel = this.db['sys_user'];
        this.roleModel = this.db['sys_role'];
        this.roleUserModel = this.db['sys_role_user'];
        this.postModel = this.db['sys_post'];
        this.userModel.belongsToMany(this.roleModel, {
            through: this.roleUserModel,
            foreignKey: 'userid',
            otherKey: 'roleid'
        })
        this.userModel.belongsToMany(this.postModel, {
            through: this.db['sys_user_post'],
            foreignKey: 'user_id',
            otherKey: 'post_id'
        })

    }


    /**
     * 获取部门及用户（根据用户角色）
     */
    async getAllUser(data) {
        try {
            return await this.userModel.findAll();

        } catch (err) {
            return this.exceptionService.handleError(err);
        }
    }
    /**
     * 获取部门及用户（根据用户角色）
     */
    async getDepartAndUser(data) {
        try {
            const userList = await this.userModel.findAll({
                include: [{
                    model: this.postModel,
                    attributes: [],
                    where: {
                        post_code: data.post_code
                    }
                }]
            });
            const orgList = await this.orgModel.findAll({
                attributes: ['id', 'org_name', 'org_code', 'parent_id']
            });
            return {
                userList: userList,
                orgList: orgList
            };
        } catch (err) {
            return this.exceptionService.handleError(err);
        }
    }
    /**
     * 根据岗位编码获取人员列表
     * @param {*} data
     */
    async getAllUserByPostCode(data) {
        try {
            return await this.userModel.findAll({
                attributes: ['id', 'username', 'realname', 'org_id'],
                include: [{
                    model: this.postModel,
                    where: {
                        post_code: data.post_code
                    },
                    attributes: []
                }]
            });
        } catch (err) {
            return this.exceptionService.handleError(err);
        }
    }
    /**
     * 信息采集员岗位评价
     * @param {} data
     */
    async getCollectEvalList(data) {
        let createDateStr = '';
        let verifyDateStr = '';
        let caseCreateDateStr = '';
        const userIDsStr = JSON.stringify(data.userList).replace('[', '(').replace(']', ')');
        try {
            const dateSource = await this.getRangeDate(data);
            if (typeof (dateSource.date) !== 'string') {
                verifyDateStr = ` and DATE_FORMAT(d.verify_date,'${dateSource.dateFormat}')>='${dateSource.date[0]}' 
                and DATE_FORMAT(d.verify_date,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`;
                createDateStr = ` and DATE_FORMAT(d.create_date,'${dateSource.dateFormat}')>='${dateSource.date[0]}' 
                and DATE_FORMAT(d.create_date,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`;
                caseCreateDateStr = ` and DATE_FORMAT(e.create_date,'${dateSource.dateFormat}')>='${dateSource.date[0]}' 
                and DATE_FORMAT(e.create_date,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`;
            } else {
                verifyDateStr = ` and DATE_FORMAT(d.verify_date,'${dateSource.dateFormat}')='${dateSource.date}'`;
                createDateStr = ` and DATE_FORMAT(d.create_date,'${dateSource.dateFormat}')='${dateSource.date}'`;
                caseCreateDateStr = ` and DATE_FORMAT(e.create_date,'${dateSource.dateFormat}')='${dateSource.date}'`;
            }
            const sql = `SELECT res.*, FORMAT(res.ownECCount/res.ownECount*100,2) as onECRate,FORMAT(res.onVerifyCount/res.verifyCount*100,2) as onVerifyRate from 
                    (SELECT a.id,a.username,a.realname,a.phone,'${dateSource.rangeDate}' as rangeDate,
                        count(case when d.verify_by = a.id and d.is_check!=0 ${verifyDateStr} then 1 ELSE null end) as 'verifyCount',
                        count(case when d.verify_by = a.id and d.is_check!=0 ${verifyDateStr} and 
                            round(TIMESTAMPDIFF(minute,d.update_date,d.verify_date),2)<30 then 1 ELSE null end) as 'onVerifyCount',
                        count(case when e.id=d.id and e.create_by=a.id ${caseCreateDateStr} then 1 ELSE null end) as 'ownECCount',
                        count(case when d.create_by=a.id ${createDateStr} then 1 ELSE null end) as 'ownECount'
                        from sys_user a
                        LEFT JOIN cms_event d on (d.create_by=a.id or d.verify_by = a.id) 
                        left join oa_case e on e.id = d.id
                        where a.id in ${userIDsStr} group by a.id) as res;`

            const sql2 = `SELECT res.*, FORMAT(res.userCount/res.orgCount*100,2) as activeRate from
                        (SELECT a.id, count( CASE WHEN e.DeptCode1 = b.id ${caseCreateDateStr} THEN 1 ELSE NULL END ) AS 'orgCount', 
                        count( CASE WHEN f.create_by = a.id AND f.id = e.id ${caseCreateDateStr} THEN 1 ELSE NULL END ) AS 'userCount' 
                        FROM sys_user a 
                        LEFT JOIN sys_org b ON b.id = a.org_id 
                        LEFT JOIN oa_case e ON e.DeptCode1 = b.id 
                        LEFT JOIN cms_event f ON f.id = e.id 
                        WHERE a.id IN ${userIDsStr} GROUP BY a.id) as res;`
            let countList = await this.CrudService.querySql(sql);
            const orgCountList = await this.CrudService.querySql(sql2);
            for (var i = 0; i < countList.length; i++) {
                for (var j = 0; j < orgCountList.length; j++) {
                    if (countList[i].id === orgCountList[j].id) {
                        countList[i] = Object.assign(countList[i], orgCountList[j]);
                    }
                }
            }
            return countList;
        } catch (err) {
            return this.exceptionService.handleError(err);
        }
    }

    /**
     * 受理人员岗位评价
     * @param {*} data
     */
    async getCenterPerEvalList(data) {
        let createDateStr = '';
        let verifyDateStr = '', updateDateStr = '';
        let endDateStr = '';
        let createEventDateStr = '';
        let verifyEventDateStr = '';
        let procDateStr = '';
        const userIDsStr = JSON.stringify(data.userList).replace('[', '(').replace(']', ')');
        try {
            const dateSource = await this.getRangeDate(data);
            if (typeof (dateSource.date) !== 'string') {
                verifyDateStr = ` and DATE_FORMAT(b.verify_date,'${dateSource.dateFormat}')>='${dateSource.date[0]}' 
                and DATE_FORMAT(b.verify_date,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`;
                createDateStr = ` and DATE_FORMAT(b.create_date,'${dateSource.dateFormat}')>='${dateSource.date[0]}' 
                and DATE_FORMAT(b.create_date,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`;
                endDateStr = ` and DATE_FORMAT(b.end_time,'${dateSource.dateFormat}')>='${dateSource.date[0]}' 
                and DATE_FORMAT(b.end_time,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`;
                updateDateStr = ` DATE_FORMAT(update_date,'${dateSource.dateFormat}')>='${dateSource.date[0]}'
                and DATE_FORMAT(update_date,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`;
                createEventDateStr = ` DATE_FORMAT(create_date,'${dateSource.dateFormat}')>='${dateSource.date[0]}'
                and DATE_FORMAT(create_date,'${dateSource.dateFormat}')<='${dateSource.date[1]}'    `
                verifyEventDateStr = ` DATE_FORMAT(verify_date,'${dateSource.dateFormat}')>='${dateSource.date[0]}'
                and DATE_FORMAT(verify_date,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`
                procDateStr = `and DATE_FORMAT(d.end_time,'${dateSource.dateFormat}')>='${dateSource.date[0]}'
                and DATE_FORMAT(d.end_time,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`
            } else {
                verifyDateStr = ` and DATE_FORMAT(b.verify_date,'${dateSource.dateFormat}')='${dateSource.date}'`;
                createDateStr = ` and DATE_FORMAT(b.create_date,'${dateSource.dateFormat}')='${dateSource.date}'`;
                endDateStr = ` and DATE_FORMAT(b.end_time,'${dateSource.dateFormat}')='${dateSource.date}'`;
                updateDateStr = `  DATE_FORMAT(update_date,'${dateSource.dateFormat}')='${dateSource.date}'`;
                createEventDateStr = `  DATE_FORMAT(create_date,'${dateSource.dateFormat}')='${dateSource.date}'`;
                verifyEventDateStr = `  DATE_FORMAT(verify_date,'${dateSource.dateFormat}')='${dateSource.date}'`;
                procDateStr = ` and DATE_FORMAT(d.end_time,'${dateSource.dateFormat}')='${dateSource.date}'`;
            }
            const sql1 = `SELECT res.*, FORMAT(res.onTaskCount/res.taskCount*100,2) as taskRate from 
                (SELECT a.id, a.username, a.realname, a.phone, '${dateSource.rangeDate}' AS rangeDate, 
                count( CASE WHEN b.task_status = 1 ${endDateStr} THEN 1 ELSE NULL END ) AS 'taskCount', 
                count( CASE WHEN b.task_status = 1 AND b.duration < 1800 ${endDateStr} THEN 1 ELSE NULL END ) AS 'onTaskCount' 
                FROM sys_user a 
                LEFT JOIN bpmn_hi_taskinst b ON b.assignee = a.username 
                WHERE a.id IN ${userIDsStr} GROUP BY a.id) as res;`;
            const sql2 = `SELECT res.*, FORMAT(res.onECCount/res.eventCaseCount*100,2) as ECRate from
                (SELECT a.id,	count(DISTINCT(b.id)) AS 'caseCount', 
                count(DISTINCT(c.id)) AS 'eventCaseCount', 
                count( CASE WHEN b.create_by = a.id AND b.id = c.id AND round( TIMESTAMPDIFF( MINUTE, c.verify_date, b.create_date ), 2 ) < 30 ${createDateStr} THEN 1 ELSE NULL END ) AS 'onECCount',
                 COUNT( DISTINCT ( CASE WHEN d.STATUS = 0 THEN d.id END )) AS 'rejectCaseCount'  ,
                 COUNT( DISTINCT ( CASE WHEN d.STATUS = 0 THEN d.id END )) AS 'obsoleteCaseCount',
					IFNULL(createEvent.createEventCount,0) createEventCount ,IFNULL(updateEvent.updateEventCount,0) updateEventCount,
					IFNULL(verifyEvent.verifyEventCount,0) verifyEventCount,IFNULL(obsoleteEvent.obsoleteEventCount,0) obsoleteEventCount
                FROM sys_user a 
                LEFT JOIN oa_case b ON b.create_by = a.id ${createDateStr}
                LEFT JOIN cms_event c ON c.id = b.id 
                 LEFT JOIN bpmn_hi_taskinst e ON e.assignee = a.username 
                LEFT JOIN bpmn_hi_procinst d ON d.id = e.proc_inst_id ${procDateStr}
                  left join  (select count(*) createEventCount,create_by from cms_event where del_flag=0 and ${createEventDateStr} GROUP BY create_by) createEvent on a.id=createEvent.create_by  
                    left join (select count(*) updateEventCount,update_by from cms_event where del_flag=0 and  ${updateDateStr} GROUP BY update_by) updateEvent on a.id=updateEvent.update_by
                    left join (select count(*) verifyEventCount,verify_by from cms_event where del_flag=0 and ${verifyEventDateStr} GROUP BY verify_by) verifyEvent on a.id=verifyEvent.verify_by 
                    left join (select count(*) obsoleteEventCount,update_by from cms_event where del_flag=0 and  status=6 and ${updateDateStr} GROUP BY update_by) obsoleteEvent on a.id=obsoleteEvent.update_by
                WHERE a.id IN ${userIDsStr} GROUP BY a.id ) as res;`;
            const sql3 = `SELECT res.*, FORMAT(res.onVECount/res.verifyEventCount*100,2) as VERate from
                (SELECT a.id,count(case when b.verify_by = a.id and b.is_check!=0 ${verifyDateStr} then 1 ELSE null end) as 'verifyEventCount',
                count(case when b.verify_by = a.id and b.is_check!=0 and round(TIMESTAMPDIFF(minute,b.update_date,b.verify_date),2)<30  ${verifyDateStr} then 1 ELSE null end) as 'onVECount'
                from sys_user a
                LEFT JOIN cms_event b on b.verify_by = a.id
                where a.id in ${userIDsStr} group by a.id) as res;`;
            let caseTaskList = await this.CrudService.querySql(sql1);
            const caseCountList = await this.CrudService.querySql(sql2);
            const eventCountList = await this.CrudService.querySql(sql3);
            for (var i = 0; i < caseTaskList.length; i++) {
                for (var j = 0; j < caseCountList.length; j++) {
                    if (caseTaskList[i].id === caseCountList[j].id) {
                        caseTaskList[i] = Object.assign(caseTaskList[i], caseCountList[j])
                    }
                }
                for (var k = 0; k < eventCountList.length; k++) {
                    if (caseTaskList[i].id === eventCountList[k].id) {
                        caseTaskList[i] = Object.assign(caseTaskList[i], eventCountList[k])
                    }
                }
            }
            return caseTaskList;
        } catch (err) {
            return this.exceptionService.handleError(err);
        }
    }

    /**
     * 其他岗位 岗位评价
     * @param {*} data
     */
    async getOhterPostEvalList(data) {
        let createDateStr = '';
        let verifyDateStr = '',updateDateStr='';
        let endDateStr = '';
        let procDateStr = '';
        const userIDsStr = JSON.stringify(data.userList).replace('[', '(').replace(']', ')');
        try {
            const dateSource = await this.getRangeDate(data);
            if (typeof (dateSource.date) !== 'string') {
                endDateStr = ` and DATE_FORMAT(b.end_time,'${dateSource.dateFormat}')>='${dateSource.date[0]}' 
                and DATE_FORMAT(b.end_time,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`;
                createDateStr=` DATE_FORMAT(create_date,'${dateSource.dateFormat}')>='${dateSource.date[0]}'
                and DATE_FORMAT(create_date,'${dateSource.dateFormat}')<='${dateSource.date[1]}'    `
                updateDateStr=` DATE_FORMAT(update_date,'${dateSource.dateFormat}')>='${dateSource.date[0]}'
                and DATE_FORMAT(update_date,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`
                verifyDateStr=` DATE_FORMAT(verify_date,'${dateSource.dateFormat}')>='${dateSource.date[0]}'
                and DATE_FORMAT(verify_date,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`
                procDateStr=`and DATE_FORMAT(c.end_time,'${dateSource.dateFormat}')>='${dateSource.date[0]}'
                and DATE_FORMAT(c.end_time,'${dateSource.dateFormat}')<='${dateSource.date[1]}'`
            } else {
                endDateStr = ` and DATE_FORMAT(b.end_time,'${dateSource.dateFormat}')='${dateSource.date}'`;
                createDateStr = `  DATE_FORMAT(create_date,'${dateSource.dateFormat}')='${dateSource.date}'`;
                updateDateStr = `  DATE_FORMAT(update_date,'${dateSource.dateFormat}')='${dateSource.date}'`;
                verifyDateStr = `  DATE_FORMAT(verify_date,'${dateSource.dateFormat}')='${dateSource.date}'`;
                procDateStr = ` and DATE_FORMAT(c.end_time,'${dateSource.dateFormat}')='${dateSource.date}'`;
            }
            const sql1 = `SELECT res.*,FORMAT(res.onApprCount/res.apprCount*100,2) as onApprRate FROM ( 
                    SELECT a.id, a.username, a.realname, a.phone, '${dateSource.rangeDate}' AS rangeDate, 
                    count( CASE WHEN b.task_status = 1 THEN 1 ELSE NULL END ) AS 'apprCount', 
                    count( CASE WHEN b.task_status = 1 AND b.duration < 1800 THEN 1 ELSE NULL END ) AS 'onApprCount', 
                    count( CASE WHEN b.task_status = 1 AND b.duration > 1800 THEN 1 ELSE NULL END ) AS 'overApprCount', 
                    count( CASE WHEN b.task_status = 1 AND b.result = 0 THEN 1 ELSE NULL END ) AS 'disApprCount', 
                    count(DISTINCT c.id) AS 'apprCaseCount', 
                    COUNT( DISTINCT ( CASE WHEN c. STATUS = 1 THEN c.id END )) AS 'endCaseCount', 
                    COUNT( DISTINCT ( CASE WHEN c. STATUS = 1 AND (c.duration <= c.overtime or c.overtime = -1) THEN c.id END )) AS 'onCaseCount', 
                    COUNT( DISTINCT ( CASE WHEN c. STATUS = 1 AND c.duration > c.overtime and c.overtime != -1 THEN c.id END )) AS 'overCaseCount', 
                    COUNT( DISTINCT ( CASE WHEN c. STATUS = 0 THEN c.id END )) AS 'unCaseCount', 
                    COUNT( DISTINCT ( CASE WHEN c. STATUS = 2 THEN c.id END )) AS 'rejectCaseCount',
					COUNT( DISTINCT ( CASE WHEN c.STATUS = 0 THEN c.id END )) AS 'obsoleteCaseCount',
					IFNULL(createEvent.createEventCount,0) createEventCount ,IFNULL(updateEvent.updateEventCount,0) updateEventCount,
					IFNULL(verifyEvent.verifyEventCount,0) verifyEventCount,IFNULL(obsoleteEvent.obsoleteEventCount,0) obsoleteEventCount
                    FROM sys_user a 
                    LEFT JOIN bpmn_hi_taskinst b ON b.assignee = a.username ${endDateStr} 
                    LEFT JOIN bpmn_hi_procinst c ON c.id = b.proc_inst_id ${procDateStr}
                    left join  (select count(*) createEventCount,create_by from cms_event where del_flag=0 and ${createDateStr} GROUP BY create_by) createEvent on a.id=createEvent.create_by  
                    left join (select count(*) updateEventCount,update_by from cms_event where del_flag=0 and ${updateDateStr} GROUP BY update_by) updateEvent on a.id=updateEvent.update_by
                    left join (select count(*) verifyEventCount,verify_by from cms_event where del_flag=0 and ${verifyDateStr} GROUP BY verify_by) verifyEvent on a.id=verifyEvent.verify_by 
                    left join (select count(*) obsoleteEventCount,update_by from cms_event where del_flag=0 and status=6 and ${updateDateStr} GROUP BY update_by) obsoleteEvent on a.id=obsoleteEvent.update_by 
                     WHERE a.id IN ${userIDsStr} GROUP BY a.id ) AS res;`


            return await this.CrudService.querySql(sql1);
        } catch (err) {
            return this.exceptionService.handleError(err);
        }
    }

    /**
     * 导出信息采集员评价excel
     * @param {*} data
     */
    async exportCollector(data) {
        let rows = [];
        const tabHead = [
            '采集员姓名', '手机号码', '及时核实次数', '核实次数', '及时核实率', '及时核实级别',
            '上报立案次数', '部门立案次数', '主动上报信息率', '主动上报级别', '主动上报立案次数',
            '主动上报次数', '信息准确率', '信息准确级别', '评价时间'
        ];
        rows.push(tabHead);
        const tabRow = [
            'realname',
            'phone',
            'onVerifyCount',
            'verifyCount',
            'onVerifyRate',
            'verifyLevel',
            'userCount',
            'orgCount',
            'activeRate',
            'activeLevel',
            'ownECCount',
            'ownECount',
            'onECRate',
            'onECLevel',
            'rangeDate'
        ];
        const list = await this.getCollectEvalList(data);
        if (list.length > 0) {
            for (var i in list) {
                let row = list[i];
                row.verifyLevel = this.gradeLevel(row.onVerifyRate);
                row.activeLevel = this.gradeLevel(row.activeRate);
                row.onECLevel = this.gradeLevel(row.onECRate);
                let arr = [];
                for (var j in tabRow) {
                    const key = tabRow[j];
                    if (row[key] !== null) {
                        arr[j] = row[key];
                    } else {
                        arr[j] = '--';
                    }
                }
                rows.push(arr);
            }
        }
        return rows;
    }

    /**
     * 导出受理人员评价列表excel
     */
    async exportCenterPerson(data) {
        let rows = [];
        const tabHead = [
            '受理员姓名', '手机号码', '派遣核实次数', '及时核实次数', '及时派遣核实率',
            '及时派遣核实级别', '批转案卷数', '及时批转案卷数', '案卷批转及时率',
            '案卷批转级别', '上报事件次数', '事件核实次数', '事件处理次数', '立案前事件作废次数', '立案后作废案件数', '作废总次数', '事件及时立案次数',
            '事件及时立案率', '事件及时立案级别', '评价时间'
        ];
        rows.push(tabHead);
        const tabRow = [
            'realname',
            'phone',
            'verifyEventCount',
            'onVECount',
            'VERate',
            'VELevel',
            'taskCount',
            'onTaskCount',
            'taskRate',
            'taskLevel',
            // 'caseCount',
            'createEventCount',
            'verifyEventCount',
            'updateEventCount',
            'obsoleteEventCount',
            'obsoleteCaseCount',
            'obsoleteCount',
            'onECCount',
            'ECRate',
            'ECLevel',
            'rangeDate'
        ];
        const list = await this.getCenterPerEvalList(data);
        if (list.length > 0) {
            for (var i in list) {
                let row = list[i];
                row.VELevel = this.gradeLevel(row.VERate);
                row.taskLevel = this.gradeLevel(row.taskRate);
                row.ECLevel = this.gradeLevel(row.ECRate);
                let arr = [];
                for (var j in tabRow) {
                    const key = tabRow[j];
                    if (row[key] !== null) {
                        if (key == 'obsoleteCount') {
                            arr[j] = row.obsoleteCaseCount + row.obsoleteEventCount;
                        } else {
                            arr[j] = row[key];
                        }
                    } else {
                        arr[j] = '--';
                    }
                }
                rows.push(arr);
            }
        }
        return rows;
    }

    /**
     * 导出其他岗位评价列表excel
     */
    async exportOtherPostPerson(data) {
        let rows = [];
        const tabHead = [
            '姓名', '手机号码', '上报事件数', '事件核实数', '事件处理数', '事件作废数', '审批次数', '及时审批次数', '超时审批次数',
            '及时审批率', '审批驳回次数', '参与案卷数', '按期案卷数', '超期结案数',
            '未结案数', '上报事件次数', '事件核实数', '事件处理次数', '立案前事件作废次数', '立案后作废案卷数', '作废总数', '评价时间'
        ];
        rows.push(tabHead);
        const tabRow = [
            'realname',
            'phone',
            'createEventCount',
            'verifyEventCount',
            'updateEventCount',
            'obsoleteEventCount',
            'apprCount',
            'onApprCount',
            'overApprCount',
            'onApprRate',
            'disApprCount',
            'apprCaseCount',
            'onCaseCount',
            'overCaseCount',
            'unCaseCount',
            'createEventCount',
            'verifyEventCount',
            'updateEventCount',
            'obsoleteEventCount',
            'obsoleteCaseCount',
            'obsoleteCount',
            'rangeDate'
        ];
        const list = await this.getOhterPostEvalList(data);
        if (list.length > 0) {
            for (var i in list) {
                let row = list[i];
                let arr = [];
                for (var j in tabRow) {
                    const key = tabRow[j];
                    if (row[key] !== null) {
                        if (key == 'obsoleteCount') {
                            arr[j] = row.obsoleteCaseCount + row.obsoleteEventCount;
                        } else {
                            arr[j] = row[key];
                        }
                    } else {
                        arr[j] = '--';
                    }
                }
                rows.push(arr);
            }
        }
        return rows;
    }
    //导出报表excel
    async exportExcel(data) {
        if (data.post_code === 'cjy') {
            return this.exportCollector(data);
        } else if (data.post_code === 'sly') {
            return this.exportCenterPerson(data);
        } else {
            return this.exportOtherPostPerson(data);
        }

    }
    async getAllPost() {
        const Op = this.db.Sequelize.Op;
        try {
            return await this.postModel.findAll({
                where: {
                    post_code: {
                        [Op.notIn]: ['cjy', 'sly']
                    }
                },
                attributes: ['id', 'post_name', 'post_code']
            });
        } catch (err) {
            return this.exceptionService.handleError(err);
        }
    }
    getRangeDate(data) {
        let dateFormat = '%Y-%m-%d';
        let date = new Date();
        let rangeDate = '';
        switch (Number(data.cycle)) {
            case 1:
                dateFormat = '%Y';
                date = data.rangeDate.substr(0, 4);
                rangeDate = `${date}`;
                break;
            case 2:
                dateFormat = '%Y-%m';
                date = data.rangeDate.substr(0, 7);
                rangeDate = `${date}`
                break;
            case 3:
                dateFormat = '%Y-%u';
                const week = this.initSearchMajorChanges(data.rangeDate);
                date = [week.monday, week.sunday]
                rangeDate = `${date[0]}—${date[1]}`;
                break;
            case 4:
                dateFormat = '%Y-%m-%d';
                date = data.rangeDate;
                rangeDate = `${date}`;
                break;
            case 5:
                dateFormat = '%Y-%m-%d';
                date = data.rangeDate2;
                rangeDate = `${date[0]}—${date[1]}`;
                break;
            default:
                break;
        }
        return {
            date: date,
            dateFormat: dateFormat,
            rangeDate: rangeDate
        };
    }


    /**
     * 根据传入日期获取周一周日
     * */
    initSearchMajorChanges(dateStr) {
        //实现当前日期对应周一，周日
        const vNowDate = moment(new moment(dateStr).format("YYYY-MM-DD")); //.add('month',0).add('days',-1);
        const vWeekOfDay = moment(vNowDate).format("E"); //算出这周的周几
        const vWeekOfDays = 7 - vWeekOfDay;
        const vStartDate = moment(vNowDate).add('days', -vWeekOfDay + 1).format("YYYY-MM-DD"); //周一
        const vEndDate = moment(vNowDate).add('days', vWeekOfDays).format("YYYY-MM-DD"); //周日
        return {
            monday: vStartDate,
            sunday: vEndDate
        };
    }


    gradeLevel(value) {
        let level = 'A';
        if (value === null) {
            level = '-';
        } else {
            const val = parseFloat(value);
            switch (true) {
                case val >= 0 && val <= 80:
                    level = 'E';
                    break;
                case val > 80 && val <= 85:
                    level = 'D';
                    break;
                case val > 85 && val < 90:
                    level = 'C';
                    break;
                case val > 90 && val <= 95:
                    level = 'B';
                    break;
                case val > 95 && val <= 100:
                    level = 'A';
                    break;
                default:
                    level = '-'
                    break;
            }
        }
        return level;
    }


}
